home *** CD-ROM | disk | FTP | other *** search
- /*
- * FireWorks module
- */
-
- OPT MODULE
-
- MODULE 'games','games/games','games/sound','*llist'
-
- EXPORT DEF explosive:PTR TO sound
-
- EXPORT SET FW_NODRAW, -> Ignored
- FW_KILLME, -> Kill this spark asap
- FW_MULTIHUE, -> Explosion will be multi-hued
- FW_MASSIVE, -> *BIG* explosion
- FW_SMALL, -> Little explosion, quick death
- FW_HGRAV, -> Heavy Gravity
- FW_BIGSPARK, -> Sparks are 3x usual size
- FW_IMAGE, -> Explode into image, negates many other flags
- FW_KEEPFLAGS,-> Children get the same flags, use with care.
- FW_EXSOUND -> Play the explosive sound.
-
- EXPORT OBJECT firework OF node
- x:LONG,y:LONG -> X,Y position
- xv:LONG,yv:LONG -> X and Y velocities
- gd:LONG -> Gravity delay
- gc:LONG -> Gravity count
- color:LONG -> Color base
- bg:LONG -> Background color at current point
- count:LONG -> Count until death
- ocount:LONG -> Death delay
- excount:LONG -> If greater than 0, this firework will explode on death,
- -> and the children will recieve self.excount-1
- flags:LONG -> Firework flags
- iw,ih:LONG -> Image HALF width/height
- ip:PTR TO CHAR -> Pointer to expimage
- ENDOBJECT
-
- CONST S_BOTTOM=185
-
- /****************************************************************************
- ** Draw the pixel into the display
- */
-
- PROC draw(scn,buf) OF firework
- DEF c,c2
-
- c:=self.color+3-((self.count*4)/self.ocount)
- c2:=self.color+3
-
- DrawPixel(scn,buf,self.x,self.y,c)
-
- IF (self.flags AND FW_BIGSPARK)
- DrawPixel(scn,buf,self.x+1,self.y,c2)
- DrawPixel(scn,buf,self.x-1,self.y,c2)
- DrawPixel(scn,buf,self.x,self.y+1,c2)
- DrawPixel(scn,buf,self.x,self.y-1,c2)
- ENDIF
- ENDPROC
-
- /****************************************************************************
- ** Blank the firework.
- */
-
- PROC clear(scn,buf) OF firework
- DrawPixel(scn,buf,self.x,self.y,self.bg)
-
- IF (self.flags AND FW_BIGSPARK)
- DrawPixel(scn,buf,self.x+1,self.y,self.bg)
- DrawPixel(scn,buf,self.x-1,self.y,self.bg)
- DrawPixel(scn,buf,self.x,self.y+1,self.bg)
- DrawPixel(scn,buf,self.x,self.y-1,self.bg)
- ENDIF
- ENDPROC
-
- /****************************************************************************
- ** Initialise new firework
- */
-
- PROC new(x,y,xv,yv,gd,color,bg,count,excount,flags,ix=NIL,iy=NIL,ip=NIL) OF firework
- self.prev:=NIL
- self.next:=NIL
- self.x:=x
- self.y:=y
- self.xv:=xv
- self.yv:=yv
- self.gd:=gd
- self.gc:=0
- self.color:=color
- self.bg:=bg
- self.count:=count
- self.ocount:=count
- self.excount:=excount
- self.flags:=flags
- self.iw:=ix
- self.ih:=iy
- self.ip:=ip
- ENDPROC
-
- /****************************************************************************
- ** Update firework
- */
-
- PROC update(flist) OF firework
-
- DEF fw:PTR TO firework,xn,yn,exsize,n,b=NIL,c,s,fl=NIL,g,yv
-
- self.x:=self.x+self.xv
- self.y:=self.y-self.yv
- IF FastRandom(5)=2 THEN self.x:=self.x+FastRandom(2)-1
- b:=(self.y>1) AND (self.y<S_BOTTOM) AND (self.x>1) AND (self.x<319)
-
- IF ((self.count>0) AND b)
- IF self.gc>self.gd
- self.gc:=0
- self.yv:=self.yv-1
- ELSE
- self.gc:=self.gc+1
- ENDIF
- self.count:=self.count-1
- ELSE
- IF b AND (self.excount>0)
- exsize:=FastRandom(10)+25
- IF (self.flags AND FW_MASSIVE)=NIL
- IF self.excount=1
- n:=FastRandom(2)+1
- ELSE
- n:=1 -> So that multi-explos don't get too big
- ENDIF
- ELSE
- self.excount:=1
- n:=5
- ENDIF
-
- IF (self.flags AND FW_SMALL)<>FALSE
- n:=1
- ENDIF
-
- IF (self.flags AND FW_KEEPFLAGS)<>FALSE THEN fl:=self.flags
- IF (self.flags AND FW_IMAGE)=FALSE
-
- IF (self.flags OR FW_BIGSPARK)
- explosive.volume := FastRandom(90)+11
- explosive.octave := FastRandom(20)*2+40
- PlaySound(explosive)
- ENDIF
-
- FOR yn:=-n TO n
- FOR xn:=-n TO n
-
- IF (self.flags AND FW_MULTIHUE) THEN c:=(FastRandom(6)*4)+8 ELSE c:=self.color
-
- IF (self.flags AND FW_SMALL)=FALSE
- s:=exsize+((FastRandom(3)-1)*10)
- ELSE
- s:=10
- ENDIF
-
- IF (self.flags AND FW_HGRAV)
- g:=1
- yv:=yn+FastRandom(3)-2
- ELSE
- g:=FastRandom(3)*6+1
- yv:=yn+self.yv+FastRandom(3)-1
- ENDIF
-
- NEW fw.new(self.x,self.y,
- xn+self.xv+FastRandom(3)-1,
- yv,
- g,
- c,
- self.bg,
- s,
- self.excount-1,
- fl)
- self.add(fw)
-
- ENDFOR
- ENDFOR
- ELSE
- FOR yn:=-self.ih TO self.ih
- FOR xn:=-self.iw TO self.iw
- c:=(self.ip[((((self.iw*2)+2)*((-yn)+self.ih))+(xn+self.iw))])
-
- IF c>0
- c:=self.color
- s:=exsize+((FastRandom(3)-1)*10)
- g:=2*6+1
- yv:=yn
-
- explosive.volume := FastRandom(90)+11
- explosive.octave := FastRandom(20)*2+40
- PlaySound(explosive)
-
- NEW fw.new(self.x,self.y,
- xn+self.xv,
- yv,
- g,
- c,
- self.bg,
- s,
- self.excount-1,
- fl)
-
- self.add(fw)
- ENDIF
- ENDFOR
- ENDFOR
- ENDIF
- ENDIF
- IF flist=self THEN flist:=self.next
- self.del()
- self.flags:=FW_KILLME
- ENDIF
- ENDPROC flist
-